<template>
  <div class="DictionaryMedicallns">
    <div class="pubBig standard">
      <div class="h0">
        <p class="lt"></p>
      </div>

      <div class="dUpMain">
        <div class="oneBox clearfix">
          <p class="p1">查询</p>
        </div>
        <div class="threeBox pucLab clearfix">
          <p>
            <label>患者姓名:</label>
            <input
              class="form-control"
              v-model="model_item_code"
              placeholder="请输入"
              type="text"
              @keyup.enter="submit1()"
              id="1"
              readonly
            />
          </p>

          <p>
            <label>身份证号:</label>
            <input
              class="form-control"
              v-model="model_item_name"
              placeholder="请输入"
              type="text"
              @keyup.enter="submit1()"
              id="2"
            />
          </p>
          <p>
            <label>申请医院:</label>
            <select
              class="form-control"
              v-model="model_item_exclude"
              placeholder="请选择"
              @change="submit1()"
              id="4"
            >
              <option
                v-for="(item,index) in model_select_item_exclude"
                :label="item.name"
                :value="item.code"
                :key="index"
              ></option>
            </select>
          </p>

          <p>
            <label>会诊类型:</label>
            <select
              class="form-control"
              v-model="model_item_exclude"
              placeholder="请选择"
              @change="submit1()"
              id="4"
            >
              <option
                v-for="(item,index) in model_select_item_exclude"
                :label="item.name"
                :value="item.code"
                :key="index"
              ></option>
            </select>
          </p>

          <p>
            <label>会诊状态:</label>
            <select
              class="form-control"
              v-model="model_item_classify"
              placeholder="请选择"
              @change="submit1()"
              id="5"
            >
              <option
                v-for="(item,index) in model_select_item_classify"
                :label="item.name"
                :value="item.code"
                :key="index"
              ></option>
            </select>
          </p>

          <p>
            <button
              class="btn btn-default"
              @click="queryz()"
            >查询</button>
          </p>
        </div>
      </div>
      <div class="dDownMain">
        <p class="p1">会诊列表</p>
        <div
          class="twoBox"
          style="top: 200px"
        >
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>会诊编号</th>
                <th>患者姓名</th>
                <th>申请医院</th>
                <th>会诊类型</th>
                <th>会诊目的</th>
                <th>申请时间</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              <tr
                v-for="(item,index) in model_query"
                :key="index"
                @click="openDetails(item,index) "
                :class="{selGreen:changeSelectStyle == index}"
              >
                <td>{{item.item_name}}</td>
                <td>{{item.item_class_Name}}</td>
                <td>{{item.item_exclude_Name}}</td>
                <td>{{item.item_classify_Name}}</td>
                <td>{{item.item_sub_classify_Name}}</td>
                <td>{{item.item_range_Name}}</td>
                <td>{{item.note}}</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "DictionaryMedicalIns",
  data () {
    return {
      msg: "SystemManagement 下的 DictionaryMedicalIns",

      //
      model_hospital_id: "",
      model_item_class: "", //医嘱类别
      model_item_classify: "", //项目分类
      model_item_code: "", //医嘱代码
      model_item_exclude: "", //排排斥类型
      model_item_name: "", //医嘱名称
      model_item_range: "", //使用范围
      model_item_sub_classify: "", //项目子类
      model_note: "", //备注
      model_pym: "", //拼音码

      model_XZBJ: "",
      model_query_BC: [],
      model_select_item_class: [], //医嘱类别
      model_select_item_classify: [], //项目分类
      model_select_item_code: [], //医嘱代码
      model_select_item_exclude: [], //排排斥类型
      model_select_item_name: [], //医嘱名称
      model_select_item_range: [], //使用范围
      model_select_item_sub_classify: [], //项目子类
      model_select_note: [], //备注
      model_select_pym: [], //拼音码

      //
      model_jmC: "",
      model_item_classC: "",
      model_item_classifyC: "",
      model_item_sub_classifyC: "",
      model_item_rangeC: "",
      model_query: [], //查询结果
      changeSelectStyle: "",

      clinic_item_dict: {
        columns: [
          { field: "item_class", title: "医嘱类别" },
          { field: "item_classify", title: "项目分类" },
          { field: "item_code", title: "医嘱代码" },
          { field: "item_exclude", title: "排斥类型" },
          { field: "item_name", title: "医嘱名称" },
          { field: "item_range", title: "使用范围" },
          { field: "item_sub_classify", title: "项目子类" },
          { field: "note", title: "备注" },
          { field: "pym", title: "拼音码" }
        ],
        data: []
      },
      currentPage: 1,
      total: 0,
      pagesize: 13
    };
  },
  methods: {
    openDetails (row, index) {
      this.model_item_class = row.item_class; //医嘱类别
      this.model_item_classify = row.item_classify; //项目分类
      this.model_item_code = row.item_code; //医嘱代码
      this.model_item_exclude = row.item_exclude; //排排斥类型
      this.model_item_name = row.item_name; //医嘱名称
      this.model_item_range = row.item_range; //使用范围
      this.model_item_sub_classify = row.item_sub_classify; //项目子类
      this.model_note = row.note; //备注
      this.model_pym = row.pym; //拼音码
      this.changeSelectStyle = index;
      console.log(row);
    },
    handleChange (val) {
      console.log(val);
    },
    //主表保存
    savez () {
      if (this.model_item_classify === "") {
        this.$message({
          showClose: true,
          message: "项目分类不能为空！",
          type: "error"
        });
        return;
      }
      // if (this.model_item_code === "") {
      //     this.$message({
      //         showClose: true,
      //         message: "医嘱代码不能为空！",
      //         type: "error"
      //     });
      //     return;
      // }
      if (this.model_item_exclude === "") {
        this.$message({
          showClose: true,
          message: "排排斥类型不能为空！",
          type: "error"
        });
        return;
      }
      if (this.model_item_name === "") {
        this.$message({
          showClose: true,
          message: "医嘱名称不能为空！",
          type: "error"
        });
        return;
      }
      if (this.model_item_range === "") {
        this.$message({
          showClose: true,
          message: "使用范围不能为空！",
          type: "error"
        });
        return;
      }
      if (this.model_item_sub_classify === "") {
        this.$message({
          showClose: true,
          message: "项目子类不能为空！",
          type: "error"
        });
        return;
      }

      var data = {
        model: "11.综合维护-医嘱字典",
        code: "11071",
        input: {
          item_class: this.model_item_class, //医嘱类别
          item_classify: this.model_item_classify, //项目分类
          item_code: this.model_item_code, //医嘱代码
          item_exclude: this.model_item_exclude, //排排斥类型
          item_name: this.model_item_name, //医嘱名称
          item_range: this.model_item_range, //使用范围
          item_sub_classify: this.model_item_sub_classify, //项目子类
          note: this.model_note, //备注
          pym: this.model_pym //拼音码
        }
      };
      this.$post("CloudHIS/Business_Handle", data)
        .then(res => {
          if (res.code == 0) {
            this.model_XZBJ = "1"
            this.$message({ message: res.msg, type: "success" });
            this.queryz();
            this.addMasterUser();
            document.getElementById("2").focus();
          } else {
            this.$message({ showClose: true, message: res.msg, type: "error" });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //删除主表信息
    deletez () {
      var data = {
        model: "11.综合维护-医嘱字典",
        code: "11073",
        input: {
          item_class: this.model_item_class,
          item_code: this.model_item_code
        }
      };
      this.$post("CloudHIS/Business_Handle", data)
        .then(res => {
          if (res.code == 0) {
            this.$message({ message: res.msg, type: "success" });
            this.queryz();
            this.addMasterUser();
          } else {
            this.$message({ showClose: true, message: res.msg, type: "error" });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //主表查询

    queryz () {
      this.model_query = [];
      var data = {
        model: "11.综合维护-医嘱字典",
        code: "11072",
        input: {
          jm: this.model_jmC ? this.model_jmC : "",
          item_class: this.model_item_classC ? this.model_item_classC : "-1", //医嘱类别
          item_classify: this.model_item_classifyC
            ? this.model_item_classifyC
            : "-1", //项目分类
          item_range: this.model_item_rangeC ? this.model_item_rangeC : "-1", //使用范围
          item_sub_classify: this.model_item_sub_classifyC
            ? this.model_item_sub_classifyC
            : "-1" //项目子类
        }
      };
      console.log(data);
      this.$post("CloudHIS/Business_Handle", data)
        .then(res => {

          if (this.model_XZBJ == "1") {
            this.model_query.push(res.data[res.data.length - 1]);
            this.model_XZBJ = "";
            this.changeSelectStyle = "0";
          } else {
            this.model_query = res.data;
            this.addMasterUser();
          }
          console.log("查询结果");
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    }, //查询公共类
    submit1 () {
      var ele = window.event.srcElement;
      var idcount = parseInt(ele.id) + 1;

      document.getElementById(idcount + "").focus();
    },
    queryG (KeyCode) {
      this.model_query = [];
      var data = {
        code: "get_sys_dict2",
        input: {
          code: KeyCode
        }
      };
      this.$post("CloudHIS/getRedisDataByCode", data)
        .then(res => {
          console.log(res); //["advice_type","Repulsion_type","item_class_code","Project_subclass","Using_range"];
          for (var i = 0; i < res.data.length; i++) {
            if (res.data[i].keycode == "advice_type") {
              this.model_select_item_class = res.data[i].dtl;
            }
            if (res.data[i].keycode == "Repulsion_type") {
              this.model_select_item_exclude = res.data[i].dtl;
            }
            if (res.data[i].keycode == "item_class_code") {
              this.model_select_item_classify = res.data[i].dtl;
            }
            if (res.data[i].keycode == "Project_subclass") {
              this.model_select_item_sub_classify = res.data[i].dtl;
            }
            if (res.data[i].keycode == "Using_range") {
              this.model_select_item_range = res.data[i].dtl;
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    addMasterUser () {
      this.model_hospital_id = "";
      this.model_item_class = ""; //医嘱类别
      this.model_item_classify = ""; //项目分类
      this.model_item_code = ""; //医嘱代码
      this.model_item_exclude = ""; //排排斥类型
      this.model_item_name = ""; //医嘱名称
      this.model_item_range = ""; //使用范围
      this.model_item_sub_classify = ""; //项目子类
      this.model_note = ""; //备注
      this.model_pym = ""; //拼音码
      document.getElementById("2").focus();
    },
    submit (item, index) {
      this.index = index;
      console.log(item);
      var arr = window.document.getElementsByTagName("input");
      for (var i = 0; i < arr.length; i++) {
        var t = arr[i];
        t.index = i;
        t.onkeydown = function (event) {
          if (event.keyCode == 13) {
            var next = this.index + 1;
            arr[next].focus();
          }
        };
      }
    },
    palction () {
      console.log(this.clinic_item_dict.data);
    },
    current_change (currentPage) {
      this.currentPage = currentPage;
      this.queryz();
    }
  },
  mounted () {
    document.getElementById("2").focus();
  },
  created () {
    if (this.$route.query.Token) {
      localStorage.setItem('Token', this.$route.query.Token)
    }
    this.queryz();
    var a = [
      "advice_type",
      "Repulsion_type",
      "item_class_code",
      "Project_subclass",
      "Using_range"
    ];
    this.queryG(a);
  }
};
</script>
<style lang="scss">
.DictionaryMedicallns {
}
</style>
